package com.nwpu.coursesupport.tool;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.nwpu.coursesupport.enumeration.Useless_EncryptionMethod;

public class EncryptionUtil {
		
	private static final int hashIterations=10;
	
	private static final Useless_EncryptionMethod algorithm=Useless_EncryptionMethod.MD5;
	
	public static String Encryption(String credentials,String salt){
		ByteSource credentialsSalt = ByteSource.Util.bytes(salt);
		Object obj = new SimpleHash(algorithm.name(), credentials, credentialsSalt, hashIterations);
		return obj.toString();
	}
	
	public static String Encryption(Useless_EncryptionMethod algorithmName,String credentials,String salt){
		ByteSource credentialsSalt = ByteSource.Util.bytes(salt);
		Object obj = new SimpleHash(algorithm.name(), credentials, credentialsSalt, hashIterations);
		return obj.toString();
	}
	
	
	public static String Encryption(Useless_EncryptionMethod algorithmName,String credentials,String salt,int hashIterations){
		ByteSource credentialsSalt = ByteSource.Util.bytes(salt);
		Object obj = new SimpleHash(algorithmName.name(), credentials, credentialsSalt, hashIterations);
		return obj.toString();
	}

}
